import Vue from 'vue'
import App from './App.vue'
import Router from 'vue-router'  //引入vue-router
import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'
import Hello from '@/components/HelloWorld'  //引入根目录下的Hello.vue组件
import ArticleRead from '@/components/ArticleRead'  //引入根目录下的Hello.vue组件
import ArticleWrite from '@/components/ArticleWrite'  //引入根目录下的Hello.vue组件
import About from '@/components/about'
import Home from '@/components/home'
// import AdminHome from '@/components/admin/home'
import Login from '@/components/login'
import VueResource from 'vue-resource'

Vue.use(VueResource );
Vue.use(mavonEditor)
Vue.use(Router)  //Vue全局使用Router

Vue.config.productionTip = false

const routes = [
  { path: '/', component: Home },
  { path: '/ArticleRead', component: ArticleRead },
  { path: '/ArticleWrite', component: ArticleWrite },
  { path: '/About', component: About },
  { path: '/Home', component: Home },
  { path: '/Login', component: Login },
  // { path: '/AdminHome', component: AdminHome }
]
const router = new Router({
      routes // routes: routes 的简写
})
//获取原型对象上的push函数
const originalPush = Router.prototype.push
//修改原型对象中的push方法
Router.prototype.push = function push(location) {
   return originalPush.call(this, location).catch(err => err)
}
const username = window.localStorage.getItem('username');
const loginStatus = window.localStorage.getItem('loginStatus');
const token = window.localStorage.getItem('token');

new Vue({
  render: h => h(App),
  router,
  data: function(){
	  return {
		  username: username == undefined ? '未登录' : username,
		  loginStatus: loginStatus == undefined ? 0 : loginStatus,
		  token: token
	  }
  },
}).$mount('#app')
